
function flickrGet(method, params, callback)
{
	if (token != null && token != "")
		params["auth_token"] = token;

	var proxyUrl = "proxy.php?method=" + method;
	for (key in params)
		proxyUrl += "&" + key + "=" + params[key];

	var xmlHttpReq = new XMLHttpRequest();
	var async = callback != null && typeof callback == "function";
	if (async) {
		xmlHttpReq.onreadystatechange = function() {
			if (this.readyState == 4)
				callback(this);
		}
	}

	xmlHttpReq.open("GET", proxyUrl, async);
	xmlHttpReq.send();

	return async ? xmlHttpReq : xmlHttpReq.responseText;
}


function flickrPost(method, params, callback, localToken)
{
	if (token != null && token != "")
		params["auth_token"] = token;

	var proxyUrl = "proxy.php";
	var requestContent = "method=" + method;
	for (key in params)
		requestContent += "&" + key + "=" + params[key];

	var xmlHttpReq = new XMLHttpRequest();
	var async = callback != null && typeof callback == "function";
	if (async) {
		xmlHttpReq.onreadystatechange = function() {
			if (this.readyState == 4)
				callback(this);
		}
	}

	xmlHttpReq.open("POST", proxyUrl, async);
	xmlHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpReq.send(requestContent);

	return async ? xmlHttpReq : xmlHttpReq.responseText;
}


function getFromFlickrSynch(method, params, displayError)
{
	var response = flickrGet(method, params);
	var json = eval("(" + response + ")");
	if (json.stat == "ok")
		return json; // thinkme: should instead return part of response that isn't 'stat'

	if (displayError == null || displayError)
		window.alert(response);
	return null;
}


function postToFlickrSynch(method, params, displayError)
{
	var response = flickrPost(method, params);
	var json = eval("(" + response + ")");
	if (json.stat && json.stat == "ok")
		return true;

	if (displayError == null || displayError)
		window.alert(response);
	return false;
}

